package cn.yhjz.admin.biz.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.admin.biz.entity.Person;
import cn.yhjz.admin.biz.vo.PersonVo;
import cn.yhjz.admin.biz.mapper.PersonMapper;
import cn.yhjz.admin.biz.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonMapper personMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, Person person) {
        Pager pager = new Pager();
        Long count = personMapper.getPageCount(person);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<PersonVo> records = personMapper.getPage(pageOffset, pageSize, person);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalCount(count);
        return pager;
    }

    @Override
    public Person insert(Person person) {
        int res = personMapper.insert(person);
        if(res > 0){
            return person;
        }else{
            return null;
        }
    }

    @Override
    public List<PersonVo> select(Person person) {
        return personMapper.select(person);
    }

    @Override
    public PersonVo selectById(Long id) {
        return personMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return personMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(Person person) {
        return personMapper.updateByIdWithNull(person);
    }

    @Override
    public int updateById(Person person) {
        return personMapper.updateById(person);
    }

    @Override
    public int update(Person entity, Person param) {
        return personMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(Person entity, Person param) {
        return personMapper.updateWithNull(entity, param);
    }
}
